<script type="text/javascript">
function preview(){
	//alert($("#pageMasthead").val());
	if($("#pageMasthead").val() == ""){
		//alert("FALSE");
		return;
		}
		//alert("TRUE");
	//alert("-----\>".$("#pageMasthead").val() );
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
			$( "#dialog-modal" ).dialog({
			height: 315,
			width: 985,
			autoopen: false,
			modal: true
		});
	
	
	$("#dialog-modal").html("<img src='/assets/masthead/"+$("#pageMasthead").val()+"'/>");
	//alert($("#dialog-modal").html());
	$("#dialog-modal").dialog();
}

function displayNavigationSelectionDialog()
{

		$( "#navigationSelection" ).dialog({
			height: 500,
			width: 810,
			modal: true,
			buttons: [{
			text: "Save",
			click: function() {
			//alert("a");
			$("#menuorderform").submit(); }
			},{
			text: "Close",
			click: function() { $(this).dialog("close"); }
			}]
		});

}





</script>

<style>
#sortable1,#sortable2,#sortable3 {
	list-style-type: none;
	margin: 0;
	padding: 0;
	float: left;
	margin-right: 10px;
	background: #eee;
	padding: 5px;
	width: 370px;
}

#sortable1 li,#sortable2 li,#sortable3 li {
	margin: 5px;
	padding: 5px;
	font-size: 1.2em;
	width: 350px;
}
</style>
<script>
$(function() {
	$( "ul.droptrue" ).sortable({
		connectWith: "ul"
	});

	$( "ul.dropfalse" ).sortable({
		connectWith: "ul",
		dropOnEmpty: false
	});

	$( "#sortable1, #sortable2").disableSelection();
});
</script>


<!-- End Header -->

<!-- Container -->
<div id="container">


	<div class="shell">

		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a> <span>&gt;</span> Current Pages
		</div>
		<?php
		$label = 'pages';
		include 'includes/message.php';
		?>

		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>

			<!-- Content -->
			<div id="content">


			<?php
			//echo (!isset($page))."----------------------------------------------".($page == '');
			if($action == ''){
				?>

				<!-- Box -->
				<div class="box" style="width: 1000px">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">Current Pages</h2>
						<div class="right">
							<label><a href="javascript:void(0)" style="color: white"
								onclick="displayNavigationSelectionDialog()">Navigation Pages in
									Site</a> </label>

						</div>
					</div>
					<!-- End Box Head -->

					<!-- Table -->
					<div class="table">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<th>Name</th>
								<th>Title</th>
								<th>Created On</th>
								<th>Date Updated</th>
								<th>Created By</th>
								<th width="110" class="ac">Content Control</th>
							</tr>


							<?php
							if ($totalRecords > 0)
							{
								$pageCounter = 1;
								foreach ($query->result() as $page)
								{
									?>
							<tr <?php if($pageCounter % 2 == 0) echo "class='odd'";?>>
								<td><h3>
										<a href="<?php echo ADMINBASEURL.'pages/edit/'.$page->id ?>"><?php echo  $page->name;?>
										</a>
									</h3></td>
								<td><?php echo  $page->title;?></td>
								<td><?php echo  $page->createdby;?></td>
								<td><?php echo  $page->updatedon;?></td>
								<td><?php echo  $page->updatedby;?></td>
								<td><a href="<?php echo ADMINBASEURL.'pages/edit/'.$page->id ?>"
									class="ico edit">Edit</a> <a
									href="<?php echo ADMINBASEURL.'pages/delete/'.$page->id ?>"
									class="ico del">Delete</a></td>
							</tr>
							<?php
							$pageCounter++;
								}
							}
							?>

						</table>

						<!-- Pagging -->
						<?php
						include 'includes/pagination.php';
						?>
						<!-- End Pagging -->

					</div>
					<!-- Table -->

				</div>
				<!-- End Box -->

				<?php
			}else{
				?>

				<!-- Box -->
				<div class="box" style="width: 1000px">
					<!-- Box Head -->
					<div class="box-head">
						<h2>Add New Pages</h2>
					</div>
					<!-- End Box Head -->

					<form action="<?php echo ADMINBASEURL."$label/save/"; ?>"
						method="post">

						<!-- Form -->
						<div class="form">
						<?php
						if($action == 'edit' && isset($pageInfo))
						echo "<input type='hidden' name='id'  value='".$pageInfo->id."'>"
								
								?>

							<p>
								<span class="req"></span> <label>Parent Page <span>(Required
										Field)</span> </label> <select class="field size3"
									style="width: 500px" name="parentid">
									<option value=''>-select-</option>
									<?php
									foreach ($pagesWithNoParent->result() as $_page)
									{
										$selected = '';
											
										if(isset($pageInfo)) {

											if($pageInfo->id ==  $_page->id)
											continue;

											$selected = ($pageInfo->parentid == $_page->id ) ? 'selected ' : '';

										}
											
											
										echo "<option $selected value='". $_page->id ."'>".$_page->name."</option>";
									}
									?>
								</select>
							</p>
							<p>
								<span class="req"></span> <label>Page Name <span>(Required
										Field)</span> </label> <input type="text" name="name"
									class="field size1" maxlength="100"
									value='<?php echo isset($pageInfo)?$pageInfo->name:''; ?>' />
							</p>
							<p>
								<span class="req"></span> <label>Page Title <span>(Required
										Field)</span> </label> <input type="text" name='title'
									class="field size1" maxlength="100"
									value='<?php echo isset($pageInfo)?$pageInfo->title:''; ?>' />
							</p>
							<!--
								<p class="inline-field">
									<label>Date</label>
									<select class="field size2">
										<option value="">23</option>
									</select>
									<select class="field size3">
										<option value="">July</option>
									</select>
									<select class="field size3">
										<option value="">2009</option>
									</select>
								</p>
								-->
							<p>
								<span class="req"></span> <label>Metadata <span>(Required Field)</span>
								</label>
								<textarea name='metadata' class="field size1"
									style="height: 65px">
									<?php echo (isset($pageInfo))?$pageInfo->metadata:''; ?>
								</textarea>
							</p>
							<p>
								<span class="req"><a href="javascript:void(0);"
									onclick="return preview()">Preview of selected Masthead</a> </span>
								<label>Masthead <span>(Required Field)</span> </label> <select
									class="field size3" style="width: 500px" id="pageMasthead"
									name="pageMasthead">
									<option value=''>-select-</option>
									<?php
									foreach ($mastheadImages as $image)
									{
										$selected = '';

										if(isset($pageInfo))
										$selected = ($pageInfo->masthead == $image ) ? 'selected ' : '';


										echo "<option $selected value='". $image."'>".$image."</option>";
									}
									?>
								</select>
							</p>


							<p>
								<span class="req"></span> <label>Page Side Navigation <span>(Required
										Field)</span> </label> <select class="field size3"
									style="width: 500px" name="pageSideNav">
									<option value=''>-select-</option>
									<?php
									foreach ($sideNavList->result() as $pNav)
									{
										$selected = '';
											
										if(isset($pageInfo))
										$selected = ($pageInfo->pagesidenav == $pNav->id ) ? 'selected ' : '';
											
											
										echo "<option $selected value='". $pNav->id ."'>".$pNav->name."</option>";
									}
									?>
								</select>
							</p>

							<p>
								<label>Content <span>(Required Field)</span> </label>
								<script type="text/javascript"
									src="/assets/ckeditor/ckeditor.js"></script>
								<textarea id="singlePage.content" name="content"
									style="height: 700px">
									<?php echo (isset($pageInfo))?$pageInfo->content:''; ?>
								</textarea>
								<script type="text/javascript">
										CKEDITOR.replace( 'singlePage.content');
									</script>
								<span class="req"></span>

							</p>

						</div>
						<!-- End Form -->

						<!-- Form Buttons -->
						<div class="buttons">
							<input type="submit" class="button" value="submit" />
						</div>
						<!-- End Form Buttons -->
					</form>
				</div>
				<!-- End Box -->

				<?php
			}
			?>

			</div>
			<!-- End Content -->

			<!-- Sidebar --
			<div id="sidebar">
				
				<!-- Box --
				<div class="box">
					
					<!-- Box Head --
					<div class="box-head">
						<h2>Management</h2>
					</div>
					<!-- End Box Head--
					
					<div class="box-content">
						<a href="#" class="add-button"><span>Add new Page</span></a>
						<div class="cl">&nbsp;</div>
						
						<p class="select-all"><input type="checkbox" class="checkbox" /><label>select all</label></p>
						<p><a href="#">Delete Selected</a></p>
						
						<!-- Sort --
						<div class="sort">
							<label>Sort by</label>
							<select class="field">
								<option value="">Title</option>
								<option value="">Date</option>
								<option value="">Author</option>
							</select>

						</div>
						<!-- End Sort --
						
					</div>
				</div>
				<!-- End Box --
			</div>
			<!-- End Sidebar -->

			<div class="cl">&nbsp;</div>
		</div>
		<!-- Main -->
	</div>
</div>
<!--
	<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
	<script src="../../jquery-1.6.2.js"></script>
	<script src="../../ui/jquery.ui.core.js"></script>
	<script src="../../ui/jquery.ui.widget.js"></script>
	<script src="../../ui/jquery.ui.mouse.js"></script>
	<script src="../../ui/jquery.ui.sortable.js"></script>
	<link rel="stylesheet" href="../demos.css">
-->




<div id="dialog-modal"
	title="Masthead"></div>

			<?php
			if($action == ''){
				?>
<div id="navigationSelection" style="display: none">

	<div class="demo" style="text-align: center">
		<table width="100%">
			<tr>
				<td>PAGES</td>
				<td>SELECTED PAGES</td>
			</tr>
		</table>
		<ul id="sortable1" class='droptrue'>
		<?php
		foreach($notSelectedPagesInMenu->result() as $notSelectedPage){
			echo '<li class="ui-state-default"><input type="hidden" name="menuorder[]" value="'.$notSelectedPage->id.'">'.$notSelectedPage->name.'</li>';
		}
		?>
		</ul>
		<form action=<?php echo ADMINBASEURL."pages/savemenuorder/"; ?>
			id="menuorderform">
			<ul id="sortable2" class='dropfalse'>

			<?php
			foreach($selectedPagesInMenu->result() as $selectedPage){
				echo '<li class="ui-state-highlight"><input type="hidden"  name="menuorder[]" value="'.$selectedPage->id.'">'.$selectedPage->name.'</li>';
			}
			?>
			</ul>
			<br clear="both" />
	
	</div>
</div>
<?php
}
?>
<!-- End Container -->
